package com.example.demotest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.DelayQueue;


public class DelayQueueDemo {

    private static Logger log = LoggerFactory.getLogger(DelayQueueDemo.class);

    public static void main(String[] args) {
        DelayQueue<DelayedDemo> sanYouTaskDelayQueue = new DelayQueue<>();

        new Thread(() -> {
            while (true) {
                try {
                    DelayedDemo sanYouTask = sanYouTaskDelayQueue.take();
                    log.info("获取到延迟任务:{}", sanYouTask.getTaskContent());
                } catch (Exception e) {
                }
            }
        }).start();

        log.info("提交延迟任务");
        sanYouTaskDelayQueue.offer(new DelayedDemo("芋道源码5s", 5L));
        sanYouTaskDelayQueue.offer(new DelayedDemo("芋道源码3s", 3L));
        sanYouTaskDelayQueue.offer(new DelayedDemo("芋道源码8s", 8L));
    }
}